package com.cwj.mansysback.service.impl;

import com.cwj.mansysback.dao.api.CourseDao;
import com.cwj.mansysback.dao.api.TeacherDao;
import com.cwj.mansysback.dao.impl.CourseDaoImpl;
import com.cwj.mansysback.dao.impl.TeacherDaoImpl;
import com.cwj.mansysback.entity.Course;
import com.cwj.mansysback.entity.Teacher;
import com.cwj.mansysback.service.api.CourseService;

import java.util.List;

public class CourseServiceImpl implements CourseService {

    private  static final CourseDao courseDao = new CourseDaoImpl();

    private  static final TeacherDao teacherDao=new TeacherDaoImpl();

    @Override
    public boolean deleteCourse(String cid) {
        return courseDao.deleteCourse(cid);
    }

    @Override
    public Course selectCourse(String cid) {
        Course course = CourseServiceImpl.courseDao.selectCourse(cid);
        if(course == null)  return null;
        Teacher teacher = CourseServiceImpl.teacherDao.selectTeacher(course.getTid());
        course.setTeacher(teacher);
        return course;
    }

    @Override
    public List<Course> selectCourseTea(String tid) {
        return courseDao.selectCourseTea(tid);
    }

    @Override
    public List<Course> selectSomeCourses(Integer pageInd, Integer rowCount, String orderKey, boolean isAsc) {
        List<Course>res = courseDao.selectSomeCourses(pageInd,rowCount,orderKey,isAsc);

        for(Course c : res){
            c.setTeacher(teacherDao.selectTeacher(c.getTid()));
        }

        return res;
    }

    @Override
    public boolean insertCourse(String cid, String cname, String tid,Integer credit) {
        return courseDao.insertCourse(cid,cname,tid,credit);
    }

    @Override
    public boolean updateCourse(String cid, String cname, String tid, Integer credit) {
        return courseDao.updateCourse(cid,cname,tid,credit);
    }
}
